using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ControleComponentParameter : MonoBehaviour
{
    public ShipUISelecter m_ShipUISelecter;
    public InputField m_ControleComponentContainer;
    public Dropdown m_ControleComponentDetailDropdown;
    WhatToDoDropDown m_WhatToDo;
    private void Awake()
    {
        m_ShipUISelecter.m_OnShipUIDroped = OnShipUIDroped;
    }
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void Init(WhatToDoDropDown whatToDo)
    {
        m_WhatToDo = whatToDo;
        m_ControleComponentContainer.text = "";
        var trigger = m_WhatToDo.GetTrigger();
        if (trigger == null)
            return;
        var comTrigger = trigger as ControleTrigger;
        if (comTrigger == null)
            return;
        m_ControleComponentContainer.text = comTrigger.shipUI.uiName;
        OnShipUIDroped(comTrigger.shipUI);
        m_ControleComponentDetailDropdown.value = comTrigger.operationType;
    }
    public void OnControleComponentOprationSelected(int value)
    {
        if (!m_WhatToDo)
            return;
        //if (value != m_ControleComponentDetailDropdown.value)
        //{
        //    m_ControleComponentDetailDropdown.value = value;
        //}
        var trigger = m_WhatToDo.GetTrigger() as ControleTrigger;
        if (null == trigger)
            return;
        trigger.operationType = value;
    }
    public void OnShipUIDroped(ShipUI shipUI)
    {
        if (!m_WhatToDo)
            return;
        var trigger = m_WhatToDo.GetTrigger() as ControleTrigger;
        if (trigger == null)
        {
            trigger = new ControleTrigger();
            m_WhatToDo.SetTrigger(trigger);
        }
        trigger.shipUI= shipUI;
        m_ControleComponentDetailDropdown.ClearOptions();
        List<string> list = shipUI.GetOperationList();
        m_ControleComponentDetailDropdown.AddOptions(list);
    }
}
